package com.kukudexin.myspringbootjpa02;


import com.kukudexin.dao.CustomerDao;
import com.kukudexin.domain.Customer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class) //声明spring提供的单元测试环境
@ContextConfiguration(locations = "classpath:applicationContext.xml")//指定spring容器的配置信息
public class SpringBootTestJqpl {

    @Autowired
    private CustomerDao customerDao;
    @Test
    public void  testFindJPQL() {
        Customer customer = customerDao.findJpql("zs");
        System.out.println(customer);
    }
    @Test
    public void testFindCustNameAndId() {
        Customer customer =  customerDao.findCustNameAndId(1l,"zs");
        System.out.println(customer);
    }
    @Test
    @Transactional //添加事务的支持
    @Rollback(value = false) //取消回滚
    public void testUpdateCustomer() {
        customerDao.updateCustomer(4l,"zl");
    }

    @Test
    public void testFindSql() {
        List<Object[]> list = customerDao.findSql("zs%");
        for(Object [] obj : list) {
            System.out.println(Arrays.toString(obj));
        }
    }

    //测试方法命名规则的查询
    @Test
    public void testNaming() {
        Customer customer = customerDao.findByCustName("zs");
        System.out.println(customer);
    }

    //测试方法命名规则的查询
    @Test
    public void testFindByCustNameLike() {
        List<Customer> list = customerDao.findByCustNameLike("zs%");
        for (Customer customer : list) {
            System.out.println(customer);
        }
    }

    //测试方法命名规则的查询
    @Test
    public void testFindByCustNameLikeAndCustIndustry() {
        Customer customer = customerDao.findByCustNameLikeAndCustIndustry("zs%", "it教育");
        System.out.println(customer);
    }
}

